#include "talkdialog.h"
#include "ui_talkdialog.h"
#include "startsettings.h"
#include "vssocket.h"
TalkDialog::TalkDialog(QWidget *parent) :
    QDialog(parent),
    ui(new Ui::TalkDialog)
{
    ui->setupUi(this);
}

TalkDialog::~TalkDialog()
{
    delete ui;
}
void TalkDialog::addMsg(QString s)
{
	text+=s;
	ui->textBrowser->setText(text);
}
void TalkDialog::onready()
{
	ui->myName_2->setText(StartSettings::socket->getNickName());
	QString s;
	s.sprintf("Player \"%s\" has join this game.\n",StartSettings::socket->getNickName().toLatin1().data());
	addMsg(s);
}

void TalkDialog::on_pushButton_clicked()
{
	if(StartSettings::socket)
	{
		QString s=StartSettings::nickName;
		s+=":"+ui->textEdit->toPlainText()+"\n";
		addMsg(s);
		ui->textEdit->clear();
		StartSettings::socket->sendTalkMessage(s);

	}
}
void TalkDialog::updateName()
{
	ui->myName->setText(StartSettings::nickName);
	ui->myName_2->setText(StartSettings::socket->getNickName());
}
